// https://www.luogu.com.cn/problem/P1880
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
int rad(); // rad int
const int max_size = 5 + 100;
const int maxn = 5 + 200;

int n;
int a[maxn], pre[maxn];
int minf[maxn][maxn], maxf[maxn][maxn];
/*
    f[l][r]: 合并 [l, r] 的得分
*/

inline int get_sum(int l, int r) { return pre[r] - pre[max(0, l - 1)]; }

int main() {
    n = rad();
    rf(i, n) a[i + n] = a[i] = rad();
    rf(i, n * 2) pre[i] = pre[i - 1] + a[i];

    for (int siz = 2; siz <= n; ++siz) {
        for (int l = 1, r = siz; r <= n * 2; ++l, ++r) {
            minf[l][r] = inf;
            for (int k = l; k + 1 <= r; ++k) {
                maxf[l][r] = max(maxf[l][r], maxf[l][k] + maxf[k + 1][r] + get_sum(l, r));
                minf[l][r] = min(minf[l][r], minf[l][k] + minf[k + 1][r] + get_sum(l, r));
            }
        }
    }

    rf(i, n) {
        rf(j, n * 2) printf("%02d ", minf[i][j]);
        puts("");
    }

    int maxa = 0, mina = inf;
    rf(i, n) {
        maxa = max(maxa, maxf[i][i + n - 1]);
        mina = min(mina, minf[i][i + n - 1]);
    }
    printf("%d\n%d", mina, maxa);
}

int rad() {
    int back = 0, ch = 0, neg = -1;
    while (ch != '-' && (ch < '0' || ch > '9'))
        ch = getchar();
    for (ch != '-' ? neg = 0 : ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return (back ^ neg) + (neg & 1);
}